//
//  NetworkMgr+Interface.m
//  AutoRental
//
//  Created by sanzhang on 1/20/14.
//  Copyright (c) 2014 zuche. All rights reserved.
//

#import "NetworkMgr+Interface.h"
#import "NSData+AES256.h"
#import "ASIHTTPRequest.h"
#import "JSON/JSONKit.h"
#import "YSDefine.h"

@implementation NetworkMgr (Interface)

- (ASIHTTPRequest *)buildRequestWithFunId:(eYylFuncID)funId option:(NSDictionary *)params
{
    NSMutableString *urlParams = [[NSMutableString alloc] initWithCapacity:128];
    
    NSString *functionStr;
    switch (funId) {
        case eAPI_START:
            functionStr = @"start.do?";
            break;
        case eAPI_LOGIN:
            functionStr = @"login.do?";
            break;
        case eAPI_REG:
            functionStr = @"reg.do?";
            break;
        case eAPI_UPDATE_MEMBER:
            functionStr = @"updateMember.do?";
            break;
        case eAPI_UPLOAD_PHOTO:
            functionStr = @"upload.do?";
            break;
        case eAPI_CHANGE_PSD:
            functionStr = @"modifyPassword.do?";
            break;
        case eAPI_ROOM_LIST:
            functionStr = @"/game/roomList.do?";
            break;
        case eAPI_SEARCH_ROOM:
            functionStr = @"/game/searchRoom.do?";
            break;
        case eAPI_PRIZE_LIST:
            functionStr = @"/prize/list.do?";
            break;
        case eAPI_PRIZE_LOTTERY:
            functionStr = @"/prize/lottery.do?";
            break;
        case eAPI_PRIZE_INFO:
            functionStr = @"/prize/updateReceivePrizeInfo.do?";
            break;
        case eAPI_RECHARGE:
            functionStr = @"/recharge/createOrder.do?";
            break;
        case eAPI_SHARE:
            functionStr = @"/share.do?";
            break;
        case eAPI_VERSION:
            functionStr = @"/checkVersion.do?";
            break;
        default:
            break;
    }
    
    ASIHTTPRequest *request;
    
    if (functionStr != nil)
    {
        [urlParams appendFormat:@"%@%@", HTTP_SERVER_URL, functionStr];
    }
    
    [urlParams appendString:[self generalParams]];
    
    if (params && [params count])
    {
        NSString *qValue = [params JSONString];
        
        [urlParams appendFormat:@"&params=%@", [[NSData AES256EncryptWithPlainTextExt:qValue] urlencode]];
    }
 
    request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlParams]];
    
    [request setTimeOutSeconds:60];
    
    return request;
}

@end
